import jwt
from flask import current_app


class JwtCode():
    def ja_jwt(self, pal):
        key = current_app.config.get('SECRET_KEY')
        token = jwt.encode(pal, key, algorithm='HS256')
        return token

    def yan_jwt(self, pay):

        # 退出token就不可使用了
        # r = Redis().red
        #
        # dr = r.找下表('code_%s' % pay)
        # if dr:
        #     return {}
        key = current_app.config.get('SECRET_KEY')
        try:
            dar = jwt.decode(pay, key, algorithms='HS256')
            return dar
        except Exception as e:
            return {}